package com.efast.dmom.mes.datahandlers.entity;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.efast.cafe.framework.util.SpringWebUtils;
import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.bean.ShiftItem;
import com.efast.dmom.mes.dao.entity.ShiftItemDao;
import com.efast.dmom.mes.datahandlers.base.ConfigurationDataHandler;
import com.efast.dmom.mes.entity.ShiftItemEntity;
import com.efast.dmom.mes.util.TimeUtil;

@Component
public class ShiftItemDataHandler extends ConfigurationDataHandler<ShiftItem>{
	@Autowired
	private ShiftItemDao shiftItemDao;
	
	@Override
	public ResultBean save(ShiftItem shiftItem) {
		ResultBean resultBean = new ResultBean();
		shiftItem.getInnerData().setSiteId(DataHandlerUtils.getSiteId());
		shiftItem.getInnerData().setCreationTime(TimeUtil.getLocalDateTime());
		shiftItem.getInnerData().setCreationTimeZone(TimeUtil.getLocalTimeZone());
		shiftItem.getInnerData().setCreator(SpringWebUtils.getRequestUser());
		shiftItem.getInnerData().setLastModifiedTime(TimeUtil.getLocalDateTime());
		shiftItem.getInnerData().setLastModifiedTimeZone(TimeUtil.getLocalTimeZone());
		shiftItem.getInnerData().setLastModifier(SpringWebUtils.getRequestUser());
//		shiftItem.getInnerData().setCreationPid(dmomIdDao.getDmomPid());
//		shiftItem.getInnerData().setLastModifiedPid(DataHandlerUtils.getDmomPid());
		shiftItem.getInnerData().setRowStatus(1);
		shiftItem.getInnerData().setRowTrxId(1);
		
		shiftItemDao.save(shiftItem.getInnerData());
		return resultBean;
	}
	
	@Override
	public ResultBean update(ShiftItem shiftItem) {
		ResultBean resultBean = new ResultBean();
		shiftItem.getInnerData().setLastModifiedTime(TimeUtil.getLocalDateTime());
		shiftItem.getInnerData().setLastModifiedTimeZone(TimeUtil.getLocalTimeZone());
		shiftItem.getInnerData().setLastModifier(SpringWebUtils.getRequestUser());
//		shiftItem.getInnerData().setLastModifiedPid(DataHandlerUtils.getDmomPid());
		shiftItem.getInnerData().setRowTrxId(1);
		
		shiftItemDao.update(shiftItem.getInnerData());
		return resultBean;
	}
	
	@Override
	public ResultBean delete(ShiftItem shiftItem) {
		ResultBean resultBean = new ResultBean();
		
	
		shiftItemDao.delete(shiftItem.getInnerData());
		
		return resultBean;
	}
	
	
	public List<ShiftItem> getShiftItemByShiftId(long shiftId){
		List<ShiftItem> shiftItems = new ArrayList<ShiftItem>();
		List<ShiftItemEntity> ShiftItemEntitys = shiftItemDao.getShiftItemByShiftId(shiftId);
		if(ShiftItemEntitys!=null&&ShiftItemEntitys.size()>0) {
		     for(ShiftItemEntity shiftItemEntity:ShiftItemEntitys) {
		    	 ShiftItem shiftItem =new ShiftItem();
		    	 shiftItem.setInnerData(shiftItemEntity);
			    shiftItems.add(shiftItem);
		}
		return shiftItems;
	}
		return null;
	}
	public ShiftItem getById(long shiftItemId) {
		ShiftItem shiftItem =new ShiftItem();
		shiftItem.setInnerData(shiftItemDao.getById(shiftItemId));
		return shiftItem;
	}
	@Override
	public ResultBean saveBatch(List<ShiftItem> obj) {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public ResultBean updateBatch(List<ShiftItem> obj) {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public ResultBean deleteBatch(List<ShiftItem> obj) {
		// TODO Auto-generated method stub
		return null;
	}
}
